package com.example.smartcity.ui.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.RealityManagementBean;

import java.util.ArrayList;

public class RealtyManagementRecAdapter extends RecyclerView.Adapter<RealtyManagementRecAdapter.MyViewHolder> {

    private ArrayList<RealityManagementBean> list;
    private int resource;

    public RealtyManagementRecAdapter(ArrayList<RealityManagementBean> list, int resource) {
        this.list = list;
        this.resource = resource;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(resource,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.IVManagerPhoto.setImageResource(list.get(position).getImageResource());
        holder.TVManagerTitle.setText(list.get(position).getManageTitle());
        holder.TVManagerMessage.setText(list.get(position).getManageMessage());
        holder.TVManagerPhone.setText(list.get(position).getManagePhone());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView IVManagerPhoto;
        private TextView TVManagerTitle;
        private TextView TVManagerMessage;
        private TextView TVManagerPhone;
        private TextView TV_Commend;
        private RecyclerView LVCommend;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            IVManagerPhoto = itemView.findViewById(R.id.IV_ManagerPhoto);
            TVManagerTitle = itemView.findViewById(R.id.TV_ManagerTitle);
            TVManagerMessage = itemView.findViewById(R.id.TV_ManagerMessage);
            TVManagerPhone = itemView.findViewById(R.id.TV_ManagerPhone);
            LVCommend = itemView.findViewById(R.id.LV_commend);
            TV_Commend = itemView.findViewById(R.id.TV_Commend);
            //评论
            TV_Commend.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.OnRCVItemClickListener(getAdapterPosition(),itemView);
                }
            });
            //拨打电话
            TVManagerPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CallListener.OnRCVItemClickListenerForCallPhone(getAdapterPosition(),itemView);
                }
            });
        }

    }


    public OnItemClickListener listener;
    public OnItemClickListenerForCallPhone CallListener;

    public void SetOnItemClickListener(OnItemClickListener listener){
        this.listener = listener;
    }
    public void SetOnRCVItemClickListenerForCallPhone(OnItemClickListenerForCallPhone CallListener){
        this.CallListener = CallListener;
    }

    public interface OnItemClickListener{
        void OnRCVItemClickListener(int position,View view);
    }

    public interface OnItemClickListenerForCallPhone{
        void OnRCVItemClickListenerForCallPhone(int position,View view);
    }
}
